package com.tzbank.poc.util;

import java.util.Collection;
import java.util.Map;

/**
 * Create by li_zheng2 on 2019/1/24.
 */
public class ValidateUtil {
    /**
     * @Description:参数不能为空或者集合类型的参数的size不能为0
     * @param argument
     * @param paramName
     * @return: T
     * @throws:
     * @Author: li_zheng2
     * @Date: 2019/1/24
     */
    public static <T> T notNullOREmpty(final T argument, final String paramName) {
       if (ValidateUtil.isEmpty(argument)) {
            throw new IllegalArgumentException(paramName + " can  not be null");
        }
        return argument;
    }

    /**
     * 判断参数是否为空
     * @param value
     * @return
     */
    public static boolean isEmpty(Object value) {
        if (value == null) {
            return true;
        }

        if (value instanceof String) {
            if (((String) value).length() == 0) {
                return true;
            }
        } else if (value instanceof Collection) {
            if (((Collection) value).size() == 0) {
                return true;
            }
        } else if (value instanceof Map) {
            if (((Map) value).size() == 0) {
                return true;
            }
        }
        return false;
    }

    public static boolean isNotEmpty(Object value) {
        if (value == null) {
            return true;
        } else if (value instanceof String) {
            return ((String)value).length() == 0;
        } else if (value instanceof Collection) {
            return ((Collection)value).size() == 0;
        } else if (value instanceof Map) {
            return ((Map)value).size() == 0;
        } else if (value instanceof CharSequence) {
            return ((CharSequence)value).length() == 0;
        } else if (value instanceof IsEmpty) {
            return ((IsEmpty)value).isEmpty();
        } else if (value instanceof Boolean) {
            return false;
        } else if (value instanceof Number) {
            return false;
        } else if (value instanceof Character) {
            return false;
        } else if (value instanceof java.util.Date) {
            return false;
        } else {
            if (Debug.verboseOn()) {
                Debug.logVerbose("In ObjectType.isEmpty(Object value) returning false for " + value.getClass() + " Object.",null);
            }

            return false;
        }
    }


}
